package com.ynny.librarysystemmanager.controller;

import com.ynny.librarysystemmanager.common.R;
import com.ynny.librarysystemmanager.entity.Book;
import com.ynny.librarysystemmanager.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookService bookService;

    @GetMapping("/list")
    public R list( Book book){

        return R.ok(bookService.findAll(book));
    }

    @PostMapping("/edit")
    public R edit(@RequestBody Book book){

        if (book.getBookId() != null){
            bookService.editBook(book);
        }else {
            bookService.addBook(book);
        }
        return R.ok(book);
    }


    @DeleteMapping("/disable/{bookId}/{status}")
    public R disable(@PathVariable ("bookId") Integer bookId,
                     @PathVariable(value = "status") Integer status){


        return R.ok(bookService.disableBook(bookId , status));

    }


}
